//
//  baseCommonMethod.m
//  baseVC
//
//  Created by 陶磊 on 2019/12/16.
//  Copyright © 2019 QHT. All rights reserved.
//

#import "baseCommonMethod.h"
#import "NSString+Hash.h"
#import "DeviceSystemHander.h"
#import <AVFoundation/AVFoundation.h>


static const NSString *baseCookieDomainAppapi = @"appapi.com.cn";
static const NSString *baseCookieDomainA = @"a.com.cn";


@implementation baseCommonMethod

//version
+ (NSString *)appVersionString{
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    return version;
}
//build
+ (NSString *)appBuildString{
    NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    return build;
}

//version(build)
+ (NSString *)appVersionAndBuildString{
    return [NSString stringWithFormat:@"%@(%@)", [self appVersionString], [self appBuildString]];
}

//UUID,IDFV
+ (NSString*)getUUID{
    NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString];
    return identifierForVendor;
}

// platform 区分安卓 ios
+ (NSString *)getPlatform{
    return @"iOS";
//    return [DeviceSystemHander getPhoneOS];
}

//JPush RegistrationID
+ (NSString *)getRegistrationID{
    NSString *RegistrationID = [[NSUserDefaults standardUserDefaults] objectForKey:@"jpush_id"];
    if (RegistrationID) {
        return RegistrationID;
    }else{
        return @"";
    }
}

// 设备当前网络状态
+ (NSString *)getPhoneCurrentNetWorkType{
    return [DeviceSystemHander getCurrentNetWorkType];
}

// 设备 和 系统版本号 iPhone 7 (10.1.1)
+ (NSString *)getPhoneDeviceTypeAndSystemVersion{
    return [DeviceSystemHander getPhoneTypeAndSystemVersion];
}

#pragma mark -- 请求参数

//每个接口必传参数
+ (NSMutableDictionary *)commonParameters{
    NSMutableDictionary *dicmutInfo = [NSMutableDictionary dictionary];
//    dicmutInfo[ZHUDeviceID] = [self getUUID]; //设备ID
//    dicmutInfo[ZHUTimeStamp] = [[NSUserDefaults standardUserDefaults] objectForKey:ZHUTimeStamp]; //时间戳
    
//    dicmutInfo[@"platform"] = [self getPlatform];
//    dicmutInfo[@"version"] = [self appVersionString];
//    dicmutInfo[@"edge"] = [self getPhoneCurrentNetWorkType];
//    dicmutInfo[@"os_version"] = [self getPhoneDeviceTypeAndSystemVersion];
    
//    dicmutInfo[@"username"] = [USERDEFAULT objectForKey:@"username"];
//    dicmutInfo[@"usercode"] = [USERDEFAULT objectForKey:@"usercode"];
//    dicmutInfo[@"mobile"] = [USERDEFAULT objectForKey:@"mobile"];
//    dicmutInfo[@"realname"] = [ZHUUSERDEFAULT objectForKey:ZHUDisplayName];

    // username and accessKey
//    [dicmutInfo addEntriesFromDictionary:[self usernameAndAccessKey]];
    
//    dicmutInfo[@"Authori-zation"] = [USERDEFAULT valueForKey:@"token"];
    
    return dicmutInfo;
}

//登陆后必传参数 (包含每个接口必传接口 添加了Uid time access_key)
//+ (NSMutableDictionary *)getAuthParmersPrefix{
//    NSMutableDictionary *dicmutInfo = [self commonParameters];
//    [dicmutInfo addEntriesFromDictionary:[self usernameAndAccessKey]];
//    return dicmutInfo;
//}

/*
//登陆后要传的参数 添加了 uid time accessKey
+ (NSMutableDictionary *)getUidAndTimeWithAccessKey {
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    long long timecha = [[userDef objectForKey:@"timeDiff"] longLongValue];//时间差
//    //开机时间
//    NSProcessInfo *info = [NSProcessInfo processInfo];
//    long long timeSystemUp =  (long long)info.systemUptime ;
    //服务器时间 = 开机时间 + 时间差
    //    long long serverTime = timeSystemUp + timecha;
    
    NSDate *newday = [NSDate date];
    long long serverTime = (long)[newday timeIntervalSince1970] + timecha;
    
    NSString *timess = [NSString stringWithFormat:@"%lld%d",serverTime,(arc4random() % 900 +100)];//加三位随机数
    long long serverTimeNow = [timess longLongValue];

    NSString *token = [userDef stringForKey:@"token"];
    NSString *uid = [userDef stringForKey:@"uid"];
    NSString *Md5Token = [token md5String];
    NSString *keys = [NSString stringWithFormat:@"%@%@%@%lld%@",uid,[self getUUID],Md5Token,serverTimeNow,CLCWAppSalt];
    NSString *access_keySha = [keys sha1String];
    if (!uid) {
        uid = @"";
    }
    NSMutableDictionary *authDic = [NSMutableDictionary dictionaryWithDictionary:@{@"uid":uid,@"time":@(serverTimeNow),@"access_key":access_keySha}];
    return authDic;
}

//H5拼接认证参数
+ (NSString *)urlStringAddParameter:(NSString *)urlStr
{
    if ([CLCWCommonMethod isLogin]) {
        //获取参数
        NSMutableDictionary *dicParater = [self getParmersPrefix];
        NSMutableDictionary *dicAuthParater = [self getUidAndTimeWithAccessKey];
        //必传参数
        NSString *platform = dicParater[@"platform"];
        NSString *uuid = dicParater[@"uuid"];
        NSString *app_Version = dicParater[@"version"]; // app版本
        NSString *push_device_id = dicParater[@"push_device_id"];
        NSString *edge = dicParater[@"edge"];
        NSString *os_version = dicParater[@"os_version"];
        //登陆后的参数
        NSString *uid = dicAuthParater[@"uid"];
        NSString *times = dicAuthParater[@"time"];
        NSString *access_key = dicAuthParater[@"access_key"];
        //解析?和&
        NSString *chainSymbol = @"?";
        if ([urlStr containsString:@"?"]) {
            chainSymbol = @"&";
        }
        NSString *newURLStr = [NSString stringWithFormat:@"%@%@uid=%@&time=%@&access_key=%@&uuid=%@&version=%@&platform=%@&push_device_id=%@&edge=%@&os_version=%@",urlStr,chainSymbol,uid,times,access_key,uuid,app_Version,platform,push_device_id,edge,os_version];
        return newURLStr;
    }else{
        //        newURLStr = [NSString stringWithFormat:@"%@%@uuid=%@&version=%@&platform=%@&push_device_id=%@&edge=%@&os_version=%@",urlStr,chainSymbol,uuid,app_Version,platform,push_device_id,edge,os_version];
        return  urlStr;
    }
}
*/

+ (NSMutableDictionary *)usernameAndAccessKey
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    
    NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:baseUserName];
    if (username && username.length) {
        [dic setObject:username forKey:baseUserName];
    }
    
    NSString *accessKey = [[NSUserDefaults standardUserDefaults] objectForKey:baseToken];
    if (accessKey && accessKey.length) {
        [dic setObject:accessKey forKey:baseToken];
    }
    return dic;
}

#pragma mark -- end

//屏幕宽度
+ (CGFloat)getScreenWidth{
    return [UIScreen mainScreen].bounds.size.width;
}
//屏幕高度
+ (CGFloat)getScreenHeight{
    return [UIScreen mainScreen].bounds.size.height;
}

//验证手机号
+(BOOL)isPhoneNumber:(NSString *)strPhone
{
    //NSString *regex = @"^((13[0-9])|(17[0-9])|(147)|(15[^4,\\D])|(18[0-9]))\\d{8}$";
    NSString *regex = @"^(13|17|14|15|18)\\d{9}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isVail = [pred evaluateWithObject:strPhone];
    if (isVail == NO) {
        [baseToast makeOnTheWindow:@"抱歉,手机号码输入有误,请输入11位数字的手机号"];
        return NO;
    }else{
        return YES;
    }
}
//判断用户名是否为空
+ (BOOL)isUserNameKong :(NSString *)String{
    if (String.length == 0) {
        [baseToast makeOnTheWindow:@"抱歉,用户名不能为空,请输入用户名"];
        return YES;
    }
    return NO;
}
//判断手机号是否为空
+ (BOOL)isPhoneNumberKong :(NSString *)textFieldStr{
    if (textFieldStr.length == 0) {
        [baseToast makeOnTheWindow:@"抱歉,手机号不能为空,请输入手机号"];
        return YES;
    }
    return NO;
}

//判断密码是否为空
+ (BOOL)isPasswordKong :(NSString *)String{
    if (String.length == 0) {
        [baseToast makeOnTheWindow:@"抱歉,密码不能为空,请输入6-16位密码"];
        return YES;
    }
    return NO;
}

//检查密码是否有效
+ (BOOL)isValidPassword:(NSString*)password{
    //判断长度
    if (password.length < 6 || password.length >16) {
        [baseToast makeOnTheWindow:@"抱歉,密码输入有误,密码应由6-16位字符组成"];
        return NO;
    }
    //判断是否包含空格
    NSRange whitespaceRange = [password rangeOfString:@" "];
    if (whitespaceRange.length) {
        [baseToast makeOnTheWindow:@"抱歉,密码输入有误,密码应由6-16位字符组成"];
        return NO;
    }
    return YES;
}

//判断验证码是否为空
+ (BOOL)isCheckNumberKong:(NSString *)String{
    if (String.length == 0) {
        [baseToast makeOnTheWindow:@"抱歉,验证码不能为空,请输入6位数字的验证码"];
        return YES;
    }
    return NO;
}

//判断字符串是否为空
+ (BOOL)isCheckStringKong:(NSString *)String msg:(NSString *)msg{
    if (String.length == 0) {
        [baseToast makeOnTheWindow:msg];
        return YES;
    }
    return NO;
}

//验证身份证号
+ (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789Xx"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

// 只保留数字，去掉其他字符
+ (NSString *)getOnlyNum:(NSString *)str
{
    
    return [str stringByReplacingOccurrencesOfString:@"[^0-9,]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [str length])];
}

#pragma mark -- 限制输入 在UITextFieldDelegate中使用
//验证输入字符串是否符合限制字符串
+ (BOOL)validateString:(NSString *)originalString limitString:(NSString *)limitString {
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:limitString] invertedSet];
    NSString *filtered = [[originalString componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    return [originalString isEqualToString:filtered];
}
// 限制输入位数 maxLength最大长度
+ (BOOL)validateTextField:(UITextField *)textField
                    range:(NSRange)range
                   string:(NSString *)string
                maxLength:(NSInteger)maxLength{
    NSUInteger oldLength = [textField.text length];
    NSUInteger replacementLength = [string length];
    NSUInteger rangeLength = range.length;
    NSUInteger newLength = oldLength - rangeLength + replacementLength;
    BOOL returnKey = [string rangeOfString: @"\n"].location != NSNotFound;
    return newLength <= maxLength || returnKey;
}

// 验证textfield输入长度,只能输入数字
+ (BOOL)validateOnlyNumberTextField:(UITextField *)textField
                              range:(NSRange)range
                             string:(NSString *)string
                          maxLength:(NSInteger)maxLength{
    BOOL isMax = [self validateTextField:textField range:range string:string maxLength:maxLength];
    BOOL isValidateStr = [self validateString:string limitString:@"0123456789"];
    return isValidateStr && isMax;
}

/** 验证textfield输入长度,只能输入字母或数字 */
+ (BOOL)validateCharacterORNumberTextField:(UITextField *)textField
                                     range:(NSRange)range
                                    string:(NSString *)string
                                 maxLength:(NSInteger)maxLength{
    BOOL isMax = [self validateTextField:textField range:range string:string maxLength:maxLength];
    BOOL isValidateStr = [self validateString:string limitString:ALLCHARACTERANDNUMBER];
    return isValidateStr && isMax;
    
}

// 验证身份证，只能输入数字和Xx，并且长度小于18位。在UITextFieldDelegate中使用
+ (BOOL)validateIDNumberTextField:(UITextField *)textField range:(NSRange)range string:(NSString *)string{
    BOOL isMax = [self validateTextField:textField range:range string:string maxLength:18];
    BOOL isValidateStr = [self validateString:string limitString:@"0123456789xX"];
    return isValidateStr && isMax;
}


//判断设备在前台后台
+(BOOL) runningInBackground
{
    UIApplicationState state = [UIApplication sharedApplication].applicationState;
    BOOL result = (state == UIApplicationStateBackground);
    return result;
}


//设置数字富文本样式
+ (NSMutableAttributedString *)getStringSignText:(NSString *)string
{
    if (string.length>0) {
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
        NSString *temp = nil;
        for(int i =0; i < [string length]; i++)
        {
            temp = [string substringWithRange:NSMakeRange(i, 1)];
            if ([self isNumber:temp]) {
                [attrStr addAttribute:NSForegroundColorAttributeName
                                value:[UIColor orangeColor]
                                range:NSMakeRange(i, 1)];
            }
        }
        return attrStr;
    }
    return nil;
}

//判断是否是数字
+ (BOOL)isNumber:(NSString *)str
{
    //NSString *regex = @"^((13[0-9])|(17[0-9])|(147)|(15[^4,\\D])|(18[0-9]))\\d{8}$";
    NSString *regex = @"[0-9]";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isVail = [pred evaluateWithObject:str];
    if (isVail == NO) {
        return NO;
    }else{
        return YES;
    }
}

//是否登录
+ (BOOL)isLogin{
    NSString *isOrLogin = [[NSUserDefaults standardUserDefaults] objectForKey:@"isOrLoginJJB"];//获取登录状态
    if (isOrLogin && [isOrLogin isEqualToString:@"loginSuccess"] ){//已经登录
        return YES;
    }else{
        return NO;
    }
}

//前台
+(BOOL) runningInForeground
{
    UIApplicationState state = [UIApplication sharedApplication].applicationState;
    BOOL result = (state == UIApplicationStateActive);
    return result;
}

//弹出UIAlertController
+ (void)alertController:(NSString *)title
                message:(NSString *)message
                     VC:(UIViewController *)VC
        eventOneHandler:(void (^)(UIAlertAction *msgString))eventOneHandler
        eventTwoHandler:(void (^)(UIAlertAction *msgString))eventTwoHandler
            alertOneStr:(NSString *)alertOneStr
            alertTwoStr:(NSString *)alertTwoStr
{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:alertOneStr  style:UIAlertActionStyleCancel handler:eventOneHandler];
    if (eventTwoHandler) {
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:alertTwoStr style:UIAlertActionStyleDefault handler:eventTwoHandler];
        [alertC addAction:okAction];
    }
    
    [alertC addAction:cancelAction];
    [VC presentViewController:alertC animated:YES completion:nil];
}

//十六进制颜色值转换成 UIcolor
+ (UIColor *)getColor:(NSString *)hexColor {
    NSString *temp = [hexColor stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSArray * Array1 = [temp componentsSeparatedByString:@"#"];
    NSString *hexColorNew = Array1[1];//转换成不带#号的字符串
    NSLog(@"%@  %@",Array1,hexColorNew);
    unsigned int red,green,blue;
    NSRange range;
    range.length = 2;
    
    range.location = 0;
    [[NSScanner scannerWithString:[hexColorNew substringWithRange:range]] scanHexInt:&red];
    
    range.location = 2;
    [[NSScanner scannerWithString:[hexColorNew substringWithRange:range]] scanHexInt:&green];
    
    range.location = 4;
    [[NSScanner scannerWithString:[hexColorNew substringWithRange:range]] scanHexInt:&blue];
    
    return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f];
}


//更新价格
+ (NSString *)updatePrice:(float)floatNumber{
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,###,###,##0.00"];
    if (floatNumber>=10000)
    {
        return [NSString stringWithFormat:@"%@万元",[numberFormatter stringFromNumber:[NSNumber numberWithDouble:floatNumber/10000]]];
    }
    else
    {
        [numberFormatter setPositiveFormat:@"###,###,###,##0"];
        return [NSString stringWithFormat:@"%@元",[numberFormatter stringFromNumber:[NSNumber numberWithDouble:floatNumber]]];
        
    }
}

//转换拍单状态
+ (NSString *)changeStateToString:(NSInteger)state{
    switch (state) {
        case -1:{
            return @"删除";
            break;
        }
        case 1:{
            return @"审核中";
            break;
        }
        case 2:{
            return @"审核驳回";
            break;
        }
        case 3:{
            return @"投标中";
            break;
        }
        case 301:{
            return @"待竞拍";
            break;
        }
        case 4:{
            return @"竞拍中";
            break;
        }
        case 5:{
            return @"待确认";
            break;
        }
        case 7:{
            return @"待签约";
            break;
        }
        case 8:{
            return @"待付首款";
            break;
        }
        case 801:{
            return @"已付首款";
            break;
        }
        case 9:{
            return @"待过户";
            break;
        }
        case 10:{
            return @"过户中";
            break;
        }
        case 11:{
            return @"待付尾款";
            break;
        }
        case 12:{
            return @"拍单失败";
            break;
        }
        case 13:{
            return @"拍单成功";
            break;
        }
    }
    return nil;
}

//毫秒转成"时:分:秒"
+ (NSString *)changeTimeInterval:(long long)millisecond{
    if (millisecond<0) {
        millisecond = 0;
    }
    long long remainSecond = millisecond/1000;
    long long hour = remainSecond/3600;
    long long minute = remainSecond%3600/60;
    long long second = remainSecond%60;
    
    NSString *timeStr = [NSString stringWithFormat:@"%02lld:%02lld:%02lld",hour,minute,second];
    return timeStr;
}

//毫秒转成"分:秒"
+ (NSString *)changeTimeIntervalToMinSec:(long long)millisecond{
    if (millisecond<0) {
        millisecond = 0;
    }
    long long remainSecond = millisecond/1000;
    long long minute = remainSecond%3600/60;
    long long second = remainSecond%60;
    
    NSString *timeStr = [NSString stringWithFormat:@"%lld:%02lld", minute, second];
    return timeStr;
}

//计算剩余时间
/*
+ (long long)calRemainTimeOrderState:(NSInteger)state
                      sceneStartTime:(long long)sceneStartTime
                    biddingStartTime:(long long)biddingStartTime
                      actElapsedTime:(long long)actElapsedTime
                      estElapsedTime:(long long)estElapsedTime{
    //默认为竞拍中
//    if (!state) {
//        state = 4;
//    }
    //剩余时间
    long long remainingTime;
    //服务器时间毫秒
    long long serverTime = [[MyHandel shareInStace] serverTime]*1000;
    //服务器偏移值
    long long offsetTime = 1000;
    
    if(state == 3){    //投标中
        remainingTime = sceneStartTime - serverTime;
        
    }else if(state == 4){     //竞标中
        //取大值
        long long elapsedTime = MAX(actElapsedTime, estElapsedTime);
        
        //剩余时间 = 竞标开始时间 + 预计时长 - 服务器时间
        remainingTime = biddingStartTime + elapsedTime - serverTime;
        
    }else if (state == 301){    //等待竞拍
        remainingTime = biddingStartTime - serverTime;
        
    }else{  //其他情况 剩余时间-1000
        remainingTime = -2000;
        
    }
    remainingTime += offsetTime;
    
    //负数了。因为有系统时间，服务器返回数据为（0-系统时间）
    if (remainingTime < 0) {
        return 0;
    }
    
    return remainingTime;
}
 */

//cell上button找到cell
+ (id)findMyCell:(Class)cellClass button:(UIButton *)btn{
    UIResponder *responder = btn.nextResponder;
    while (responder) {
        if ([responder isKindOfClass:cellClass]) {
            return responder;
        }
        responder = responder.nextResponder;
    }
    return nil;
}

//dealerID
+ (NSInteger)dealerID{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSInteger dealerID = [[userDefault objectForKey:@"dealer_id"] integerValue];
    return dealerID;
}

//dealerID
+ (NSString *)dealerIDStr{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"dealer_id"];
}

//判断null
+ (BOOL)isNull:(id)obj{
    if (obj && ![obj isKindOfClass:[NSNull class]]) {
        return YES;
    }
    return NO;
}

+ (BOOL)isNull:(id)obj isClass:(Class)isClass{
    if ([self isNull:obj]) {
        if ([obj isKindOfClass:isClass]) {
            return YES;
        }
    }
    return NO;
}

+ (BOOL)isNull:(NSDictionary *)dic key:(NSString *)key{
    return [self isNull:[dic objectForKey:key]];
}

+ (BOOL)isNull:(NSDictionary *)dic key:(NSString *)key isClass:(Class)isClass{
    id obj = [dic objectForKey:key];
    //判断是否为空
    if ([self isNull:obj]) {
        //判断类型是否相同
        if ([obj isKindOfClass:isClass]) {
            //判断是否是字典，判断字典个数（额外的）
//            if ([obj isKindOfClass:[NSArray class]]) {
//                NSArray *array = (NSArray *)obj;
//                if (array.count) {
//                    return YES;
//                }
//            }
            
            return YES;
        }
    }
    return NO;
}

//返回当前值或者nil
+ (id)checkNull:(id)obj{
    if ([self isNull:obj]) {
        return obj;
    }
    return nil;
}

+ (id)checkNull:(id)obj isClass:(Class)isClass{
    if ([self isNull:obj] && [obj isKindOfClass:isClass]) {
        return obj;
    }
    return nil;
}

+ (id)dictionary:(NSDictionary *)dictionary objectForKey:(NSString *)key{
    return [self checkNull:[dictionary objectForKey:key]];
}

/* 判空格式化json数据
 * string, integer, null, true, false, array, dictionary To string
 */
+ (NSString *)stringFormat:(id)obj {
    if ([obj isKindOfClass:[NSString class]]) {
        return [NSString stringWithFormat:@"%@", obj];
    }
    return nil;
}

//请求header中cookie增加审核字段
+ (void)requestAddCookieAuditing{
    NSArray *cookieArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
    for (NSHTTPCookie *cookie in cookieArray) {
        if ([cookie.name isEqualToString:@"Auditing"]) {
            return;
        }
    }
    NSDictionary *cookieDic = @{
                                NSHTTPCookieName: @"Auditing",
                                NSHTTPCookieValue: @"True",
                                NSHTTPCookieDomain: baseCookieDomainAppapi,
                                NSHTTPCookiePath: @"/"//默认路径
                                };
    NSHTTPCookie *cookie = [[NSHTTPCookie alloc]initWithProperties:cookieDic];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
    
    NSDictionary *cookieOtherDic = @{
                                NSHTTPCookieName: @"Auditing",
                                NSHTTPCookieValue: @"True",
                                NSHTTPCookieDomain: baseCookieDomainA,
                                NSHTTPCookiePath: @"/"//默认路径
                                };
    NSHTTPCookie *cookieOther = [[NSHTTPCookie alloc]initWithProperties:cookieOtherDic];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookieOther];
}


//删除header中cookie增加的审核字段
+ (void)requestDeleteCookieAuditing{
    NSArray *cookiesArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
    for (NSHTTPCookie *cookie in cookiesArray) {
        if ([cookie.name isEqualToString:@"Auditing"]) {
            [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
        }
    }
}

//根据auditing状态设置cookie
+ (void)cookieSetupWithAuditing {
    BOOL isAuditing = [[NSUserDefaults standardUserDefaults] boolForKey:@"isAuditing"];
    if (isAuditing) {
        //cookie增加审核环境字段
        [baseCommonMethod requestAddCookieAuditing];
    }else{
        //删除cookie相关字段
        [baseCommonMethod requestDeleteCookieAuditing];
    }
}

//跳转webView(无交互页面)
/*
+ (void)pushWebviewVC:(NSString *)titleStr UrlStr:(NSString *)UrlStr VC:(UIViewController *)VC {
    RuleVC *vc = [[RuleVC alloc]init];
    vc.titles = titleStr;
    vc.urlStr = UrlStr;
    [VC.navigationController pushViewController:vc animated:YES];
}
*/

//颜色转为UIimage
+ (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

//获得公钥
/*
+ (void)getPublicKeyFromNetWorking:(void (^)(NSString *str))resultString{
    NSMutableDictionary *dicInfo = [NSMutableDictionary dictionary];//请求参数
    [[MyHandel shareInStace]RequstDataStr3:URLGetRsaKey result:^(NSMutableDictionary *respondata) {
        resultString(respondata[@"data"]);
    } Parameter:dicInfo];
}

//查询弹框
+ (void)alertTanSeacher:(NSString *)priceSeacherStr alertTanView:(AlertTextAndButtonview *)alertTanView {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if (priceSeacherStr) { //查询价格
        [[NSUserDefaults standardUserDefaults] setObject:priceSeacherStr forKey:@"seacehr_WeiBaoPrice"];
    }
    [alertTanView setupSubViewsBackViewColor:[UIColor whiteColor] titlabStr:@"温馨提示" titlabTextColor:UICColorNewBlue desLab:[NSString stringWithFormat:@"本次查询收费%@元",priceSeacherStr] desLabColor:[UIColor blackColor] countBtn:2 leftBtnStr:@"取消" rightBtnStr:@"确定"];
    alertTanView.layer.cornerRadius = 5;
    alertTanView.layer.masksToBounds = YES;
    
    UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0,0, KWidth, KHight)];
    downView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
    downView.tag = 1111;
    [window addSubview:downView];
    [downView addSubview:alertTanView];
    [alertTanView addGestureRecognizer:[UITapGestureRecognizer new]];
}
*/
//充值弹框
/*
+ (void)alertViewTanisOrPayVC:(AlertOnlyTextView *)alertView{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [alertView setupSubViews:[UIColor whiteColor] titlabStr:@"温馨提示" titlabTextColor:UICColorNewBlue desLab:@"您的保证金不足,无法查询请及时充值" desLabColor:[UIColor blackColor] countBtn:2 leftBtnStr:@"取消" rightBtnStr:@"立即充值"];
    alertView.layer.cornerRadius = 5;
    alertView.layer.masksToBounds = YES;
    
    UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0,0, KWidth, KHight)];
    downView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
    downView.tag = 1111;
    [window addSubview:downView];
    [downView addSubview:alertView];
    [alertView addGestureRecognizer:[UITapGestureRecognizer new]];
}
*/
+ (NSMutableAttributedString *)activityLabdataString:(NSString *)string range:(NSRange)rangeMake textColor:(UIColor *)textColor font:(NSInteger)font{
    //富文本
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:string];
    if (string.length) {
        [AttributedStr addAttribute:NSFontAttributeName
                              value:[UIFont systemFontOfSize:font]
                              range:rangeMake];
        [AttributedStr addAttribute:NSForegroundColorAttributeName
                              value:textColor
                              range:rangeMake];
    }
    return  AttributedStr;
}

//查询配置表(最外层字段)
+ (id)getConfigDataFromString:(NSString *)string{
    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
    NSData *configData =  [userDef objectForKey:@"ConfigData"];
    NSMutableDictionary * configDic = [NSJSONSerialization JSONObjectWithData:configData options:1 error:nil];
    id seacherConfigStr = configDic[string];
    
    if (!seacherConfigStr || seacherConfigStr == [NSNull null]) {
        return  @"..";
    }else{
        return seacherConfigStr;
    }
}

//show toast
+ (void)showToast:(NSString *)toastString{
    [baseToast makeOnTheWindow:toastString];
}

//暂无数据
+ (void)NoDateWarnNoDataView:(UIView *)dataView addToSelfView:(UIView *)viewSelf ImgString:(NSString *)imgString titString:(NSString *)titString{
    //暂无数据downView
    dataView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWidth, KHeight-64)];
    dataView.backgroundColor = [UIColor whiteColor];
    [viewSelf addSubview:dataView];
    //图片
    CGFloat displayHeight = KHeight-20-44-49;
    UIImageView *bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgString]];
    bgImageView.frame = CGRectMake(0, displayHeight/2-50-155-8, 160, 155);
    bgImageView.center = CGPointMake(KWidth/2.0, bgImageView.center.y);
    [dataView addSubview:bgImageView];
    //文字lab
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.frame = CGRectMake(0, displayHeight/2-45, KWidth, 20);
    titleLabel.text = titString;
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [dataView addSubview:titleLabel];
    
}

/**
 获得1像素高度
 @return 1像素高度
 */
+ (CGFloat)onePixel {
    return 1.0/[UIScreen mainScreen].scale;
}

#pragma mark -- UITableViewCell
//tableview注册cell 多余cell不显示
+ (void)tableView:(UITableView *)tableView registerNib:(NSString *)nibStr {
    [tableView registerNib:[UINib nibWithNibName:nibStr bundle:nil] forCellReuseIdentifier:nibStr];
}

//tableview设置
+ (void)tableViewSetting:(UITableView *)tableView registerNib:(NSString *)nibStr{
    [self tableView:tableView registerNib:nibStr];
    tableView.tableFooterView = [[UIView alloc] init];//多余cell不显示
//    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    tableView.separatorColor = [UIColor separator];

}

+ (UITableViewCell *)defaultTableViewCell:(UITableView *)tableView{
    static NSString *identifier = @"identifier";
    UITableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!tableViewCell) {
        tableViewCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return tableViewCell;
}


#pragma mark -- custom constraint
/**
 在baseView与subView之间增加上下左右四个0的约束
 @param baseView 其实可以互换
 @param subView 应该是可以互换
 */
+ (void)constraintBaseView:(UIView *)baseView subView:(UIView *)subView {
    subView.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint * l = [NSLayoutConstraint constraintWithItem:subView
                                                          attribute:NSLayoutAttributeLeading
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:baseView
                                                          attribute:NSLayoutAttributeLeading
                                                         multiplier:1.0
                                                           constant:0];
    NSLayoutConstraint * r = [NSLayoutConstraint constraintWithItem:subView
                                                          attribute:NSLayoutAttributeTrailing
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:baseView
                                                          attribute:NSLayoutAttributeTrailing
                                                         multiplier:1.0
                                                           constant:0];
    NSLayoutConstraint * t = [NSLayoutConstraint constraintWithItem:subView
                                                          attribute:NSLayoutAttributeTop
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:baseView
                                                          attribute:NSLayoutAttributeTop
                                                         multiplier:1.0
                                                           constant:0];
    NSLayoutConstraint * b = [NSLayoutConstraint constraintWithItem:subView
                                                          attribute:NSLayoutAttributeBottom
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:baseView
                                                          attribute:NSLayoutAttributeBottom
                                                         multiplier:1.0
                                                           constant:0];
    //不执行添加代码会crash
    [baseView addSubview:subView];
    [NSLayoutConstraint activateConstraints:@[l, r, t, b]];
}

#pragma mark -- formatNSString
+ (NSString *)formatStr:(NSString *)str {
    return [NSString stringWithFormat:@"%@", str];
}

//去掉头尾回车符
+ (NSString *)getPublicKeyCertString:(NSString *)certDataString
{
    //    NSString *base64String = [[NSString alloc] initWithData:certData encoding:NSUTF8StringEncoding] ;
    NSString *repleas = [certDataString stringByReplacingOccurrencesOfString:@"-----BEGIN CERTIFICATE-----" withString:@""];
    NSString *replea = [repleas stringByReplacingOccurrencesOfString:@"-----END CERTIFICATE-----" withString:@""];
    NSString *reple = [replea stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSString *repl = [reple stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    return repl;
}

+ (CGFloat)labHight:(UIFont* )aFont width:(float )aWidth text:(NSString* )aStr{
    CGSize size = CGSizeMake(aWidth,CGFLOAT_MAX);
    NSDictionary *attribute = @{NSFontAttributeName:aFont};
    CGSize labelsize = [aStr boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
    return labelsize.height;
}

+ (CGFloat)labWidth:(UIFont* )aFont hight:(float )aHeight text:(NSString* )aStr{
    CGSize size = CGSizeMake(CGFLOAT_MAX,aHeight);
    NSDictionary *attribute = @{NSFontAttributeName:aFont};
    NSString *a = [NSString stringWithFormat:@"%@",aStr];
    CGSize labelsize = [a boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
    return labelsize.width;
}

//获取图片文件名
+(NSString *)gettimeFileName{
    NSDate *currentDate = [NSDate date];
    NSString *timeChuo = [NSString stringWithFormat:@"%lld",(long long)[currentDate timeIntervalSince1970]];
    NSString *uuid = [self getUUID];
    NSString *last8 = [uuid substringFromIndex:uuid.length- 4 ];//uuid后4位
    NSString *fileName = [NSString stringWithFormat:@"%@%u-%@.png",timeChuo,(arc4random() % 900 +100),last8];
    return fileName;
}


#pragma mark -- 时间
//获取当前时间
+(NSString *)getMonth{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYYMM"];
    NSString *DateTime = [formatter stringFromDate:date];
    return DateTime;
}

// 获取当前这种格式时间 2017-12-5 09:58:21
+ (NSString *)formattedDate
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:date];
}

// 获取当前这种格式时间 2017-12-5 09:58:21
+ (NSString *)formattedDate:(NSString *)str
{
    NSTimeInterval time = [str doubleValue]/1000;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:date];
}

// 获取当前这种格式时间 2017-12-5 09:58
+ (NSString *)formattedDateyyyyMMddHHmm:(NSString *)str
{
    NSTimeInterval time = [str doubleValue]/1000;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    return [formatter stringFromDate:date];
}


// 获取当前时间，这种格式 2017-12-5
+ (NSString *)formattedDateYMD
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter stringFromDate:date];
}

// 获取当前日期，这种格式 2017125
+ (NSString *)formattedDateyyyyMMdd
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMdd"];
    return [formatter stringFromDate:date];
}

// 获取这种格式时间 2017-12-5
+ (NSString *)formattedDateYMD:(NSString *)str
{
    NSTimeInterval time = [str doubleValue]/1000;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter stringFromDate:date];
}

/**
 处理时间格式 将2018-01-01 15:39格式处理为2018-01-01
 */
+ (NSString *)interceptString:(NSString *)str
{
    NSRange range = [str rangeOfString:@" "];
    if (range.location == NSNotFound) {
        return str;
    }
    NSRange srange = {0, range.location};
    NSString *newString = [str substringWithRange:srange];
    return newString;
}

/**
 拼接成新字符串
 */
+ (NSString *)interceptString:(NSString *)startStr withEndString:(NSString *)endStr
{
    return [NSString stringWithFormat:@"%@至%@", [self interceptString:startStr], [self interceptString:endStr]];
}

// 获取时间戳(毫秒)
+ (NSString *)systemTimestamp
{
    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;
    return [NSString stringWithFormat:@"%.0f", interval];
}

// 时间戳(毫秒)+3位随机数
+ (NSString *)systemTimestampWithThreeNumber
{
    NSInteger arcNumber = arc4random()%900+100;
    return [NSString stringWithFormat:@"%@%ld", [baseCommonMethod systemTimestamp], arcNumber];
}

// NSDate转周几
+ (NSString *)dateToWeek:(NSDate *)date
{
    NSArray *weekStrArray = @[@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六"];
    NSInteger weekDay = [[NSCalendar currentCalendar] component:NSCalendarUnitWeekday fromDate:date];
    return weekStrArray[weekDay-1];
}

//转换成json字符串
+ (NSString *)getJsonStringData:(id)data{
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    return jsonString;
}

//Json字符串转化成id类型数据
+ (id)getDataFromJsonStr:(NSString *)jsonString{
    if (nil == jsonString) {
        return nil;
    }
    id alldata = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments | NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers error:nil];
    return alldata;
}

#pragma mark -- json
+ (BOOL)toBOOL:(NSObject *)obj
{
    if ([obj isKindOfClass:[NSNumber class]]) {
        NSNumber *number = (NSNumber *)obj;
        return [number boolValue];
    }else if ([obj isKindOfClass:[NSString class]]) {
        NSString *str = (NSString *)obj;
        if ([str isEqualToString:@"yes"]) {
            return YES;
        }
    }
    return NO;
}

+ (NSInteger)toInteger:(NSObject *)obj {
    if ([obj isKindOfClass:[NSNumber class]]) {
        NSNumber *number = (NSNumber *)obj;
        return [number integerValue];
    }else if ([obj isKindOfClass:[NSString class]]) {
        NSString *str = (NSString *)obj;
        return [str integerValue];
    }else {//array, object, null, nil
        return 0;
    }
}

+ (NSString *)toString:(NSObject *)obj {
    if ([obj isKindOfClass:[NSNumber class]]) {
        NSNumber *number = (NSNumber *)obj;
        return [NSString stringWithFormat:@"%@", number];
    }else if ([obj isKindOfClass:[NSString class]]) {
        NSString *str = (NSString *)obj;
        return str;
    }else {//array, object, null, nil
        return nil;
    }
}

+ (NSArray *)toArray:(NSObject *)obj {
    if ([obj isKindOfClass:[NSArray class]]) {
        NSArray *array = (NSArray *)obj;
        return array;
    }else {
        return nil;
    }
}

+ (NSDictionary *)toDictionary:(NSObject *)obj {
    if ([obj isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dic = (NSDictionary *)obj;
        return dic;
    }else {
        return nil;
    }
}

#pragma mark -- storyboard
+ (__kindof UIViewController *)instantiateVCWithName:(NSString *)name ID:(NSString *)identifier
{
    return [[UIStoryboard storyboardWithName:name bundle:nil] instantiateViewControllerWithIdentifier:identifier];
}

#pragma mark -- 价格转换
+ (NSString *)priceAddSymbol:(CGFloat)price WithThousands:(BOOL)isThousand
{
    if (isThousand) {
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
        numberFormatter.maximumFractionDigits = 2;
        numberFormatter.minimumFractionDigits = 2;
        NSString *numberStr = [NSString stringWithFormat:@"¥%@", [numberFormatter stringFromNumber:@(price)]];
        return numberStr;
    }
    return [NSString stringWithFormat:@"¥%.2f", price];
}

#pragma mark -- 拼接图片地址
+ (NSURL *)urlWithStringAddHeader:(NSString *)str
{
    if (![str hasPrefix:@"http"]) {
//        NSString *baseURL = [[NSUserDefaults standardUserDefaults] objectForKey:@"baseURL"];
//        NSString *port = [[NSUserDefaults standardUserDefaults] objectForKey:@"port"];
        NSString *httpStr = [NSString stringWithFormat:@"%@%@", baseURL, str];
        return [NSURL URLWithString:httpStr];
    }
    return [NSURL URLWithString:str];
}


// 获取视频第一帧
+ (UIImage*)getVideoPreViewImage:(NSURL *)path
{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:path options:nil];
    AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    
    assetGen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(0, 10000);
    NSError *error = nil;
    CMTime actualTime;
    CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];
    UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];
    CGImageRelease(image);
    return videoImage;
}


#pragma mark -- 语音识别
+ (NSArray<NSString *> *)getNumberFromString:(NSString *)text
{
    if (!text.length) {
        return nil;
    }
    NSScanner *scanner = [NSScanner scannerWithString:text];
    NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    
    NSMutableArray *array = [NSMutableArray array];
    while (!scanner.isAtEnd) {
        NSString *buffer = [NSString string];
        if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
            [array addObject:buffer];
        }else {
            [scanner setScanLocation:([scanner scanLocation]+1)];
        }
    }
    return array;
}

// 比较两个float类型是否相同
+ (BOOL)isFloatEqual:(CGFloat)number1 number:(CGFloat)number2
{
    CGFloat resultFloat = fabs(number1 - number2);
    if (resultFloat < 0.000001) {
        return YES;
    }
    return NO;
}

+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

/** 金额四舍五入*/
+ (NSString *)decimalwithFormat:(CGFloat)floatV{
   NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
   [numberFormatter setPositiveFormat:@"0.000"];
   NSString *sNum = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:floatV]];
   return  [sNum substringToIndex:sNum.length-1];
}

// NSDictionary 转 jsonString
+ (NSString *)convertNSDictionaryToJsonString:(NSDictionary *)json {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&error];
    if (error) {
        NSLog(@"json解析失败:%@", error);
        return nil;
    }
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    return jsonString;
}
//比较时间大小
+ (int)compareOneDay:(NSDate*)oneDay withAnotherDay:(NSDate*)anotherDay

{

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat:@"yy年MM月dd日 HH:mm"];

    NSString*oneDayStr = [dateFormatter stringFromDate:oneDay];

    NSString*anotherDayStr = [dateFormatter stringFromDate:anotherDay];

    NSDate*dateA = [dateFormatter dateFromString:oneDayStr];

    NSDate*dateB = [dateFormatter dateFromString:anotherDayStr];

    NSComparisonResult result = [dateA compare:dateB];

    if (result == NSOrderedDescending) {

        //在指定时间前面 过了指定时间 过期
        return 1;
    }else if(result ==NSOrderedAscending){
        //没过指定时间 没过期
        //NSLog(@"Date1 is in the past");
        return-1;
    }
    //刚好时间一样.
    //NSLog(@"Both dates are the same");
    return 0;

}

@end
